import 'package:flutter_fun_app/model/userModel.dart';
import 'package:flustars/flustars.dart';

class Setting {
  static const String ZH = "zh";
  static const String EN = "en";

  static bool isLogin() {
    return SpUtil.getBool('isLogin', defValue: false);
  }

  static void setLogin(bool flag) {
    String lang = getLang();
    SpUtil.clear();
    SpUtil.putBool("isLogin", flag);
    setLang(lang);
  }

  static void setLang(String lang) {
    SpUtil.putString("lang", lang);
  }

  static String getLang() {
    return SpUtil.getString("lang");
  }

  static void saveUserInfo(UserInfo model) {
    if (model != null) {
      SpUtil.putString("key", model.key);
      SpUtil.putString("phone", model.phone);
      SpUtil.putString("name", model.name);
      SpUtil.putString("passwd", model.passwd);
      SpUtil.putString("text", model.text);
      SpUtil.putString("img", model.img);
      SpUtil.putString("other", model.other);
      SpUtil.putString("other2", model.other2);
      SpUtil.putString("createTime", model.createTime);
    }
  }

  static UserInfo getUserInfo() {
    String key = SpUtil.getString('key');
    String phone = SpUtil.getString('phone');
    String name = SpUtil.getString('name');
    String passwd = SpUtil.getString('passwd');
    String text = SpUtil.getString('text');
    String img = SpUtil.getString('img');
    String other = SpUtil.getString('other');
    String other2 = SpUtil.getString('other2');
    String createTime = SpUtil.getString('createTime');
    return UserInfo(
        createTime, img, key, name, other, other2, passwd, phone, text);
  }
}
